package com.shop.controller;

import com.shop.entity.ShopProduct;
import com.shop.service.ShopProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    ShopProductService shopProductService;

    @GetMapping("/")
    public String load(Model model) {

        List<ShopProduct> shopProductList = shopProductService.GetShopProductList();
        model.addAttribute("shopProducts", shopProductList);
        return "/index";
    }

    @RequestMapping("/productDetail")
    public String productDetail(@RequestParam("id") int shopProId, Model model) {


        ShopProduct shopProduct = shopProductService.GetShopProductById(shopProId);
        model.addAttribute("shopProDetail", shopProduct);

        return "single-product";
    }

}
